<ui:composition template="/pages/templates/layout-admin.xhtml"
	xmlns="http://www.w3.org/1999/xhtml"
	xmlns:ui="http://java.sun.com/jsf/facelets"
	xmlns:f="http://java.sun.com/jsf/core"
	xmlns:h="http://java.sun.com/jsf/html"
	xmlns:p="http://primefaces.org/ui">

	<ui:define name="title">Enregistrement des utilisateurs</ui:define>
	<ui:define name="content">
		<h:form id="form">
			<p:messages id="messages" showDetail="true" autoUpdate="true"
				closable="true" />

			<p:panel id="toggleable" header="ENREGISTREMENT DES UTILISATEURS"
				toggleable="true" toggleSpeed="500" widgetVar="panel">
				<p:fieldset id="saisie" legend="Saisie des informations"
					toggleable="true" toggleSpeed="500">
					<h:panelGrid columns="3" cellpadding="10">
						<p:outputLabel for="userPseudo" value="Pseudo" />
						<p:inputText id="userPseudo"
							value="#{userBean.currentUser.userPseudo}" required="true">
						</p:inputText>
						<p:message id="userPseudoMsg" for="userPseudo" display="icon" />

						<p:outputLabel for="userPass" value="Mot de passe" />
						<p:inputText id="userPass"
							value="#{userBean.currentUser.userPassword}" required="true">
						</p:inputText>
						<p:message id="userPassMsg" for="userPass" display="icon" />

						<p:outputLabel for="role" value="Role" />
						<p:autoComplete id="role"
							value="#{userBean.selectedUserRoleCombo}"
							completeMethod="#{userBean.completeUserRole}" var="roleUs"
							itemLabel="#{roleUs.userRoleLibelle}" itemValue="#{roleUs}"
							converter="#{entityConverter}" dropdown="true"
							forceSelection="true" required="true" effect="bounce"
							styleClass="select">
							<p:ajax update="roleMsg" event="query" global="false" />
						</p:autoComplete>
						<p:message id="roleMsg" for="role" display="icon" />

						<h:outputText value="Activer " />
						<p:selectBooleanCheckbox
							value="#{userBean.currentUser.userEnabled}" />
					</h:panelGrid>

					<p:separator />

					<p:commandButton value="Enrégistrer" binding="#{userBean.btnSave}"
						action="#{userBean.saveUser}" icon="ui-icon-disk" update="@all">
						<p:confirm header="Confirmation"
							message="Voulez-vous enrégistrer ?" icon="ui-icon-alert" />
					</p:commandButton>
					<p:commandButton value="Modifier" binding="#{userBean.btnUpdate}"
						action="#{userBean.updateUser}" icon="ui-icon-refresh"
						update="@all" disabled="true">
						<p:confirm header="Confirmation" message="Voulez-vous modifier ?"
							icon="ui-icon-alert" />
					</p:commandButton>
					<p:commandButton value="Supprimer" binding="#{userBean.btnDelete}"
						action="#{userBean.deleteUser}" icon="ui-icon-trash" update="@all"
						disabled="true">
						<p:confirm header="Confirmation" message="Voulez-vous supprimer ?"
							icon="ui-icon-alert" />
					</p:commandButton>
					<p:commandButton value="Annuler" action="#{userBean.resetField}"
						icon="ui-icon-cancel" update=":form:saisie" />

					<p:confirmDialog global="true" showEffect="puff"
						hideEffect="explode">
						<p:commandButton value="Oui" type="button"
							styleClass="ui-confirmdialog-yes" icon="ui-icon-check" />
						<p:commandButton value="Non" type="button"
							styleClass="ui-confirmdialog-no" icon="ui-icon-close" />
					</p:confirmDialog>
				</p:fieldset>

				<p:dataTable id="table" var="user" value="#{userBean.users}"
					selection="#{userBean.selectedUser}" selectionMode="single"
					rowKey="#{user.userId}"
					paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
					paginator="true" rows="10" rowsPerPageTemplate="5,10,15"
					styleClass="table">
					<p:ajax event="rowSelect" listener="#{userBean.updateField}"
						update=":form:saisie" />
					<p:column headerText="Identifiants" styleClass="column">
						<h:outputText value="#{user.userId}" />
					</p:column>
					<p:column headerText="Pseudos" styleClass="column">
						<h:outputText value="#{user.userPseudo}" />
					</p:column>
					<p:column headerText="Mot de passes" styleClass="column">
						<h:outputText value="#{user.userPassword}" />
					</p:column>
					<p:column headerText="Actifs" styleClass="column">
						<h:outputText value="#{user.userEnabled}" />
					</p:column>

					<p:column headerText="Roles" styleClass="column">
						<h:outputText value="#{user.userRole.userRoleLibelle}" />
					</p:column>
				</p:dataTable>
			</p:panel>
		</h:form>
	</ui:define>
</ui:composition>
